package com.ken.controller.admin;

import com.ken.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Slf4j
@Api("店铺操作接口")
public class ShopController {
    @Autowired
    private StringRedisTemplate redisTemplate;

    @GetMapping("/status")
    @ApiOperation("获取营业状态")
    public Result<String> getStatus(){
        String s = redisTemplate.opsForValue().get("SHOP_STATUS");
        log.info("当前店铺的营业状态为:{}",Integer.parseInt(s)==1?"营业中":"已打样");
        return Result.success(s);
    }

    @PutMapping("/{status}")
    @ApiOperation("设置营业状态")
    public Result<String> setStatus(@PathVariable String status){
        log.info("设置店铺的营业状态为:{}",Integer.parseInt(status)==1?"营业中":"已打样");
        redisTemplate.opsForValue().set("SHOP_STATUS",status);
        return Result.success();
    }

}
